<template>
  <div>
    <!-- 随机文章推荐 -->
    <div class="random-article">
      <h2 class="title fz18">随机文章推荐</h2>
      <ul class="list flex-direction-column">
        <li class="item" v-for="item in romArticle" :key="item._id">
          <router-link :to="`/article-detail/${item._id}`"> {{ item.title }} </router-link>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { getRandomArticleLsit } from '@/api/article'
export default {
  name: 'RandomList',
  data() {
    return {
      romArticle: []
    }
  },
  props: {
    width: {
      type: String,
      default: '160px'
    }
  },
  created() {
    this.getRanArticle()
  },
  methods: {
    async getRanArticle() {
      try {
        const res = await getRandomArticleLsit({ limit: 5 })
        console.log(res)
        this.romArticle = res.data
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.random-article {
  width: v-bind(width);
  padding: 10px;
  border-radius: 5px;
  background-color: #fff;
  margin-top: 20px;
  margin-bottom: 20px;
  .title {
    padding: 10px 0 10px 0;
    font-weight: 600;
    border-bottom: 1px solid #eee;
  }
  .item {
    padding: 5px 0 2.5px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    a {
      font-size: 13px;
      color: #666;
      &:hover {
        color: skyblue;
        text-decoration: underline;
      }
    }
  }
}
</style>
